<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['list']=array();
	$return['params']['type']=1;
	$return['params']['status']=0;
	$return['post']=array('mid'=>'');
	exi($return);
}
if($_RQ['op']=='list'){	
	$params=array('uniacid'=>$_SESSION['uniacid'],'adminmid'=>$_SESSION['uid']);
	$page=intval($_RQ['page']);
	if(!$page){
		$page=1;
	}
	$limit=array($page,10);
	$list=pdo_getslice('jy_yuejie_worker',$params,$limit,$total,'','','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['totalprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid'],'ispay'=>1),'price');
			$item['totalprice']=$item['totalprice']?:'0.00';
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'status'=>intval($postdata['status']),
		'cfee'=>intval($postdata['cfee']),
	);
	$id=$postdata['id'];
	if($id){
		pdo_update('jy_yuejie_worker',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('设置成功！','','/worker/list/');
	}else{
		if(!$postdata['mid']){
			exi('请输入员工会员ID！','error');
		}
		$check=pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$postdata['mid'],'merchid'=>0));
		if(!$check['id']){
			exi('该会员不存在！无法添加员工！','error');
		}
		$data['status']=1;
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$postdata['mid'];
		$data['adminmid']=$_SESSION['uid'];
		$data['createtime']=time();
		pdo_insert('jy_yuejie_worker',$data);
		pdo_update('jy_weishop_member',array('yuejie_type'=>2),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$postdata['mid'],'merchid'=>0));
		exi('添加成功！','','/worker/list/');
	}
}
if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择员工！','error');
	}
	if($id){
		$worker=pdo_get('jy_yuejie_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		pdo_delete('jy_yuejie_worker',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_weishop_member',array('yuejie_type'=>0),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$worker['mid'],'merchid'=>0));
	}
	exi('删除成功！');
}